package org.cs.calculatemachine;

/**
 * 运算器
 *
 * @author fbin
 * @since 2022/4/5 11:15
 */
public class CalculateMachine {
    /**
     * 累加器
     */
    private static final Accumulator ACC;

    /**
     * 算术逻辑单元
     */
    private static final ArithmeticAndLogicUnit ALU;

    /**
     * 乘积商寄存器
     */
    private static final MultipleQuotientRegister MQR;

    /**
     * 通用的操作数寄存器
     */
    private static final X X;

    static {
        ACC = new Accumulator();
        ALU = new ArithmeticAndLogicUnit();
        MQR = new MultipleQuotientRegister();
        X = new X();
    }

    public void setToAcc(int num) {
        ACC.setNum(num);
    }

    public void add(int num) {
        ACC.setNum(ALU.add(ACC.getNum(), num));
    }

    public void reduce(int num) {
        ACC.setNum(ALU.reduce(ACC.getNum(), num));
    }

    public int getFromAcc() {
        return ACC.getNum();
    }
}
